/*
#Copyright (c) 2013, Philippe Bordron <philippe.bordron@gmail.com>
#
# This file is part of SIPPER.
#
# DCC is free software: you can redistribute it and/or modify
# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU LESSER GENERAL PUBLIC LICENSE for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# along with SIPPER.  If not, see <http://www.gnu.org/licenses/>
*/
package combi.wip.utils;

import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

public class Bloc<R,G> {

	private String id;
	private List<List<R>> reactions;
	private List<List<G>> genes;
	private double score; 

	public Bloc(String id)
	{
		this.id = id;
		reactions = new LinkedList<List<R>>();
		genes = new LinkedList<List<G>>();
	}
	public Bloc(Bloc<R,G> bloc)
	{
		this.id = bloc.id;
		this.reactions = new LinkedList<List<R>>(bloc.reactions);
		this.genes = new LinkedList<List<G>>(bloc.genes);
		this.score = bloc.score;
	}
	
	public Bloc(String id, double score)
	{
		this.id = id;
		reactions = new LinkedList<List<R>>();
		genes = new LinkedList<List<G>>();
		setScore(score);
	}
	
	public double setScore(double score)
	{
		this.score = score;
		return score;
	}
	
	public void add(List<R> lr, List<G> lg)
	{
		reactions.add(lr);
		genes.add(lg);
	}
	
	public double getScore(){
		return this.score;
	}
	
	public int getSize()
	{
		return (reactions.size());
	}
	
	public String getId()
	{
		return id;
	}
	
	public Set<R> getReactions(Collection<Integer> selection)
	{
		Set<R> result = new HashSet<R>();
		for (Integer i : selection)
		{
			result.addAll(getReactions(i));
		}
		return result;
	}
	

	public Set<G> getGenes(Collection<Integer> selection)
	{
		Set<G> result = new HashSet<G>();
		for (Integer i : selection)
		{
			result.addAll(getGenes(i));
		}
		return result;
	}
	
	
	public Set<R> getReactions()
	{
		Set<R> result = new HashSet<R>();
		for (List<R> l : reactions)
		{
			result.addAll(l);
		}
		return result;
	}
	
	public List<R> getReactions(int k)
	{
		List<R> result = reactions.get(k);
		return result;
	}

	public List<G> getGenes(int k)
	{
		List<G> result = genes.get(k);
		return result;
	}
	
	public Set<G> getGenes()
	{
		Set<G> result = new HashSet<G>();
		for (List<G> l : genes)
		{
			result.addAll(l);
		}
		return result;
	}
	
	public void clear()
	{
		this.reactions.clear();
		this.genes.clear();
	}
	
	public String toString(){
		return id +"\nreactions: "+reactions.toString()+"\ngenes: "+genes.toString();
	}
	
	public String toStringBis()
	{
		String sip ="";
		for (int i=0; i<genes.size(); i++)
		{
			
		}
		return id +"\nreactions: "+reactions.toString()+"\ngenes: "+genes.toString();
	}

}
